<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">


<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    
    <title>django.contrib.humanize &mdash; Django 1.7.8.dev20150401230226 documentation</title>
    
    <link rel="stylesheet" href="../../_static/default.css" type="text/css" />
    <link rel="stylesheet" href="../../_static/pygments.css" type="text/css" />
    
    <script type="text/javascript">
      var DOCUMENTATION_OPTIONS = {
        URL_ROOT:    '../../',
        VERSION:     '1.7.8.dev20150401230226',
        COLLAPSE_INDEX: false,
        FILE_SUFFIX: '.html',
        HAS_SOURCE:  true
      };
    </script>
    <script type="text/javascript" src="../../_static/jquery.js"></script>
    <script type="text/javascript" src="../../_static/underscore.js"></script>
    <script type="text/javascript" src="../../_static/doctools.js"></script>
    <link rel="top" title="Django 1.7.8.dev20150401230226 documentation" href="../../index.html" />
    <link rel="up" title="contrib packages" href="index.html" />
    <link rel="next" title="The messages framework" href="messages.html" />
    <link rel="prev" title="Deploying GeoDjango" href="gis/deployment.html" />



 
<script type="text/javascript" src="../../templatebuiltins.js"></script>
<script type="text/javascript">
(function($) {
    if (!django_template_builtins) {
       // templatebuiltins.js missing, do nothing.
       return;
    }
    $(document).ready(function() {
        // Hyperlink Django template tags and filters
        var base = "../templates/builtins.html";
        if (base == "#") {
            // Special case for builtins.html itself
            base = "";
        }
        // Tags are keywords, class '.k'
        $("div.highlight\\-html\\+django span.k").each(function(i, elem) {
             var tagname = $(elem).text();
             if ($.inArray(tagname, django_template_builtins.ttags) != -1) {
                 var fragment = tagname.replace(/_/, '-');
                 $(elem).html("<a href='" + base + "#" + fragment + "'>" + tagname + "</a>");
             }
        });
        // Filters are functions, class '.nf'
        $("div.highlight\\-html\\+django span.nf").each(function(i, elem) {
             var filtername = $(elem).text();
             if ($.inArray(filtername, django_template_builtins.tfilters) != -1) {
                 var fragment = filtername.replace(/_/, '-');
                 $(elem).html("<a href='" + base + "#" + fragment + "'>" + filtername + "</a>");
             }
        });
    });
})(jQuery);
</script>


  </head>
  <body>

    <div class="document">
  <div id="custom-doc" class="yui-t6">
    <div id="hd">
      <h1><a href="../../index.html">Django 1.7.8.dev20150401230226 documentation</a></h1>
      <div id="global-nav">
        <a title="Home page" href="../../index.html">Home</a>  |
        <a title="Table of contents" href="../../contents.html">Table of contents</a>  |
        <a title="Global index" href="../../genindex.html">Index</a>  |
        <a title="Module index" href="../../py-modindex.html">Modules</a>
      </div>
      <div class="nav">
    &laquo; <a href="gis/deployment.html" title="Deploying GeoDjango">previous</a>
     |
    <a href="../index.html" title="API Reference" accesskey="U">up</a>
   |
    <a href="messages.html" title="The messages framework">next</a> &raquo;</div>
    </div>

    <div id="bd">
      <div id="yui-main">
        <div class="yui-b">
          <div class="yui-g" id="ref-contrib-humanize">
            
  <div class="section" id="s-module-django.contrib.humanize">
<span id="s-django-contrib-humanize"></span><span id="module-django.contrib.humanize"></span><span id="django-contrib-humanize"></span><h1>django.contrib.humanize<a class="headerlink" href="#module-django.contrib.humanize" title="Permalink to this headline">¶</a></h1>
<p>A set of Django template filters useful for adding a &#8220;human touch&#8221; to data.</p>
<p>To activate these filters, add <tt class="docutils literal"><span class="pre">'django.contrib.humanize'</span></tt> to your
<a class="reference internal" href="../settings.html#std:setting-INSTALLED_APPS"><tt class="xref std std-setting docutils literal"><span class="pre">INSTALLED_APPS</span></tt></a> setting. Once you&#8217;ve done that, use
<tt class="docutils literal"><span class="pre">{%</span> <span class="pre">load</span> <span class="pre">humanize</span> <span class="pre">%}</span></tt> in a template, and you&#8217;ll have access to the following
filters.</p>
<div class="section" id="s-apnumber">
<span id="s-std:templatefilter-apnumber"></span><span id="apnumber"></span><span id="std:templatefilter-apnumber"></span><h2>apnumber<a class="headerlink" href="#apnumber" title="Permalink to this headline">¶</a></h2>
<p>For numbers 1-9, returns the number spelled out. Otherwise, returns the
number. This follows Associated Press style.</p>
<p>Examples:</p>
<ul class="simple">
<li><tt class="docutils literal"><span class="pre">1</span></tt> becomes <tt class="docutils literal"><span class="pre">one</span></tt>.</li>
<li><tt class="docutils literal"><span class="pre">2</span></tt> becomes <tt class="docutils literal"><span class="pre">two</span></tt>.</li>
<li><tt class="docutils literal"><span class="pre">10</span></tt> becomes <tt class="docutils literal"><span class="pre">10</span></tt>.</li>
</ul>
<p>You can pass in either an integer or a string representation of an integer.</p>
</div>
<div class="section" id="s-intcomma">
<span id="s-std:templatefilter-intcomma"></span><span id="intcomma"></span><span id="std:templatefilter-intcomma"></span><h2>intcomma<a class="headerlink" href="#intcomma" title="Permalink to this headline">¶</a></h2>
<p>Converts an integer to a string containing commas every three digits.</p>
<p>Examples:</p>
<ul class="simple">
<li><tt class="docutils literal"><span class="pre">4500</span></tt> becomes <tt class="docutils literal"><span class="pre">4,500</span></tt>.</li>
<li><tt class="docutils literal"><span class="pre">45000</span></tt> becomes <tt class="docutils literal"><span class="pre">45,000</span></tt>.</li>
<li><tt class="docutils literal"><span class="pre">450000</span></tt> becomes <tt class="docutils literal"><span class="pre">450,000</span></tt>.</li>
<li><tt class="docutils literal"><span class="pre">4500000</span></tt> becomes <tt class="docutils literal"><span class="pre">4,500,000</span></tt>.</li>
</ul>
<p><a class="reference internal" href="../../topics/i18n/formatting.html#format-localization"><em>Format localization</em></a> will be respected if enabled,
e.g. with the <tt class="docutils literal"><span class="pre">'de'</span></tt> language:</p>
<ul class="simple">
<li><tt class="docutils literal"><span class="pre">45000</span></tt> becomes <tt class="docutils literal"><span class="pre">'45.000'</span></tt>.</li>
<li><tt class="docutils literal"><span class="pre">450000</span></tt> becomes <tt class="docutils literal"><span class="pre">'450.000'</span></tt>.</li>
</ul>
<p>You can pass in either an integer or a string representation of an integer.</p>
</div>
<div class="section" id="s-intword">
<span id="s-std:templatefilter-intword"></span><span id="intword"></span><span id="std:templatefilter-intword"></span><h2>intword<a class="headerlink" href="#intword" title="Permalink to this headline">¶</a></h2>
<p>Converts a large integer to a friendly text representation. Works best for
numbers over 1 million.</p>
<p>Examples:</p>
<ul class="simple">
<li><tt class="docutils literal"><span class="pre">1000000</span></tt> becomes <tt class="docutils literal"><span class="pre">1.0</span> <span class="pre">million</span></tt>.</li>
<li><tt class="docutils literal"><span class="pre">1200000</span></tt> becomes <tt class="docutils literal"><span class="pre">1.2</span> <span class="pre">million</span></tt>.</li>
<li><tt class="docutils literal"><span class="pre">1200000000</span></tt> becomes <tt class="docutils literal"><span class="pre">1.2</span> <span class="pre">billion</span></tt>.</li>
</ul>
<p>Values up to 10^100 (Googol) are supported.</p>
<p><a class="reference internal" href="../../topics/i18n/formatting.html#format-localization"><em>Format localization</em></a> will be respected if enabled,
e.g. with the <tt class="docutils literal"><span class="pre">'de'</span></tt> language:</p>
<ul class="simple">
<li><tt class="docutils literal"><span class="pre">1000000</span></tt> becomes <tt class="docutils literal"><span class="pre">'1,0</span> <span class="pre">Million'</span></tt>.</li>
<li><tt class="docutils literal"><span class="pre">1200000</span></tt> becomes <tt class="docutils literal"><span class="pre">'1,2</span> <span class="pre">Million'</span></tt>.</li>
<li><tt class="docutils literal"><span class="pre">1200000000</span></tt> becomes <tt class="docutils literal"><span class="pre">'1,2</span> <span class="pre">Milliarden'</span></tt>.</li>
</ul>
<p>You can pass in either an integer or a string representation of an integer.</p>
</div>
<div class="section" id="s-naturalday">
<span id="s-std:templatefilter-naturalday"></span><span id="naturalday"></span><span id="std:templatefilter-naturalday"></span><h2>naturalday<a class="headerlink" href="#naturalday" title="Permalink to this headline">¶</a></h2>
<p>For dates that are the current day or within one day, return &#8220;today&#8221;,
&#8220;tomorrow&#8221; or &#8220;yesterday&#8221;, as appropriate. Otherwise, format the date using
the passed in format string.</p>
<p><strong>Argument:</strong> Date formatting string as described in the <a class="reference internal" href="../templates/builtins.html#std:templatefilter-date"><tt class="xref std std-tfilter docutils literal"><span class="pre">date</span></tt></a> tag.</p>
<p>Examples (when &#8216;today&#8217; is 17 Feb 2007):</p>
<ul class="simple">
<li><tt class="docutils literal"><span class="pre">16</span> <span class="pre">Feb</span> <span class="pre">2007</span></tt> becomes <tt class="docutils literal"><span class="pre">yesterday</span></tt>.</li>
<li><tt class="docutils literal"><span class="pre">17</span> <span class="pre">Feb</span> <span class="pre">2007</span></tt> becomes <tt class="docutils literal"><span class="pre">today</span></tt>.</li>
<li><tt class="docutils literal"><span class="pre">18</span> <span class="pre">Feb</span> <span class="pre">2007</span></tt> becomes <tt class="docutils literal"><span class="pre">tomorrow</span></tt>.</li>
<li>Any other day is formatted according to given argument or the
<a class="reference internal" href="../settings.html#std:setting-DATE_FORMAT"><tt class="xref std std-setting docutils literal"><span class="pre">DATE_FORMAT</span></tt></a> setting if no argument is given.</li>
</ul>
</div>
<div class="section" id="s-naturaltime">
<span id="s-std:templatefilter-naturaltime"></span><span id="naturaltime"></span><span id="std:templatefilter-naturaltime"></span><h2>naturaltime<a class="headerlink" href="#naturaltime" title="Permalink to this headline">¶</a></h2>
<p>For datetime values, returns a string representing how many seconds,
minutes or hours ago it was &#8211; falling back to the <a class="reference internal" href="../templates/builtins.html#std:templatefilter-timesince"><tt class="xref std std-tfilter docutils literal"><span class="pre">timesince</span></tt></a>
format if the value is more than a day old. In case the datetime value is in
the future the return value will automatically use an appropriate phrase.</p>
<p>Examples (when &#8216;now&#8217; is 17 Feb 2007 16:30:00):</p>
<ul class="simple">
<li><tt class="docutils literal"><span class="pre">17</span> <span class="pre">Feb</span> <span class="pre">2007</span> <span class="pre">16:30:00</span></tt> becomes <tt class="docutils literal"><span class="pre">now</span></tt>.</li>
<li><tt class="docutils literal"><span class="pre">17</span> <span class="pre">Feb</span> <span class="pre">2007</span> <span class="pre">16:29:31</span></tt> becomes <tt class="docutils literal"><span class="pre">29</span> <span class="pre">seconds</span> <span class="pre">ago</span></tt>.</li>
<li><tt class="docutils literal"><span class="pre">17</span> <span class="pre">Feb</span> <span class="pre">2007</span> <span class="pre">16:29:00</span></tt> becomes <tt class="docutils literal"><span class="pre">a</span> <span class="pre">minute</span> <span class="pre">ago</span></tt>.</li>
<li><tt class="docutils literal"><span class="pre">17</span> <span class="pre">Feb</span> <span class="pre">2007</span> <span class="pre">16:25:35</span></tt> becomes <tt class="docutils literal"><span class="pre">4</span> <span class="pre">minutes</span> <span class="pre">ago</span></tt>.</li>
<li><tt class="docutils literal"><span class="pre">17</span> <span class="pre">Feb</span> <span class="pre">2007</span> <span class="pre">15:30:29</span></tt> becomes <tt class="docutils literal"><span class="pre">59</span> <span class="pre">minutes</span> <span class="pre">ago</span></tt>.</li>
<li><tt class="docutils literal"><span class="pre">17</span> <span class="pre">Feb</span> <span class="pre">2007</span> <span class="pre">15:30:01</span></tt> becomes <tt class="docutils literal"><span class="pre">59</span> <span class="pre">minutes</span> <span class="pre">ago</span></tt>.</li>
<li><tt class="docutils literal"><span class="pre">17</span> <span class="pre">Feb</span> <span class="pre">2007</span> <span class="pre">15:30:00</span></tt> becomes <tt class="docutils literal"><span class="pre">an</span> <span class="pre">hour</span> <span class="pre">ago</span></tt>.</li>
<li><tt class="docutils literal"><span class="pre">17</span> <span class="pre">Feb</span> <span class="pre">2007</span> <span class="pre">13:31:29</span></tt> becomes <tt class="docutils literal"><span class="pre">2</span> <span class="pre">hours</span> <span class="pre">ago</span></tt>.</li>
<li><tt class="docutils literal"><span class="pre">16</span> <span class="pre">Feb</span> <span class="pre">2007</span> <span class="pre">13:31:29</span></tt> becomes <tt class="docutils literal"><span class="pre">1</span> <span class="pre">day,</span> <span class="pre">2</span> <span class="pre">hours</span> <span class="pre">ago</span></tt>.</li>
<li><tt class="docutils literal"><span class="pre">16</span> <span class="pre">Feb</span> <span class="pre">2007</span> <span class="pre">13:30:01</span></tt> becomes <tt class="docutils literal"><span class="pre">1</span> <span class="pre">day,</span> <span class="pre">2</span> <span class="pre">hours</span> <span class="pre">ago</span></tt>.</li>
<li><tt class="docutils literal"><span class="pre">16</span> <span class="pre">Feb</span> <span class="pre">2007</span> <span class="pre">13:30:00</span></tt> becomes <tt class="docutils literal"><span class="pre">1</span> <span class="pre">day,</span> <span class="pre">3</span> <span class="pre">hours</span> <span class="pre">ago</span></tt>.</li>
<li><tt class="docutils literal"><span class="pre">17</span> <span class="pre">Feb</span> <span class="pre">2007</span> <span class="pre">16:30:30</span></tt> becomes <tt class="docutils literal"><span class="pre">30</span> <span class="pre">seconds</span> <span class="pre">from</span> <span class="pre">now</span></tt>.</li>
<li><tt class="docutils literal"><span class="pre">17</span> <span class="pre">Feb</span> <span class="pre">2007</span> <span class="pre">16:30:29</span></tt> becomes <tt class="docutils literal"><span class="pre">29</span> <span class="pre">seconds</span> <span class="pre">from</span> <span class="pre">now</span></tt>.</li>
<li><tt class="docutils literal"><span class="pre">17</span> <span class="pre">Feb</span> <span class="pre">2007</span> <span class="pre">16:31:00</span></tt> becomes <tt class="docutils literal"><span class="pre">a</span> <span class="pre">minute</span> <span class="pre">from</span> <span class="pre">now</span></tt>.</li>
<li><tt class="docutils literal"><span class="pre">17</span> <span class="pre">Feb</span> <span class="pre">2007</span> <span class="pre">16:34:35</span></tt> becomes <tt class="docutils literal"><span class="pre">4</span> <span class="pre">minutes</span> <span class="pre">from</span> <span class="pre">now</span></tt>.</li>
<li><tt class="docutils literal"><span class="pre">17</span> <span class="pre">Feb</span> <span class="pre">2007</span> <span class="pre">17:30:29</span></tt> becomes <tt class="docutils literal"><span class="pre">an</span> <span class="pre">hour</span> <span class="pre">from</span> <span class="pre">now</span></tt>.</li>
<li><tt class="docutils literal"><span class="pre">17</span> <span class="pre">Feb</span> <span class="pre">2007</span> <span class="pre">18:31:29</span></tt> becomes <tt class="docutils literal"><span class="pre">2</span> <span class="pre">hours</span> <span class="pre">from</span> <span class="pre">now</span></tt>.</li>
<li><tt class="docutils literal"><span class="pre">18</span> <span class="pre">Feb</span> <span class="pre">2007</span> <span class="pre">16:31:29</span></tt> becomes <tt class="docutils literal"><span class="pre">1</span> <span class="pre">day</span> <span class="pre">from</span> <span class="pre">now</span></tt>.</li>
<li><tt class="docutils literal"><span class="pre">26</span> <span class="pre">Feb</span> <span class="pre">2007</span> <span class="pre">18:31:29</span></tt> becomes <tt class="docutils literal"><span class="pre">1</span> <span class="pre">week,</span> <span class="pre">2</span> <span class="pre">days</span> <span class="pre">from</span> <span class="pre">now</span></tt>.</li>
</ul>
</div>
<div class="section" id="s-ordinal">
<span id="s-std:templatefilter-ordinal"></span><span id="ordinal"></span><span id="std:templatefilter-ordinal"></span><h2>ordinal<a class="headerlink" href="#ordinal" title="Permalink to this headline">¶</a></h2>
<p>Converts an integer to its ordinal as a string.</p>
<p>Examples:</p>
<ul class="simple">
<li><tt class="docutils literal"><span class="pre">1</span></tt> becomes <tt class="docutils literal"><span class="pre">1st</span></tt>.</li>
<li><tt class="docutils literal"><span class="pre">2</span></tt> becomes <tt class="docutils literal"><span class="pre">2nd</span></tt>.</li>
<li><tt class="docutils literal"><span class="pre">3</span></tt> becomes <tt class="docutils literal"><span class="pre">3rd</span></tt>.</li>
</ul>
<p>You can pass in either an integer or a string representation of an integer.</p>
</div>
</div>


          </div>
        </div>
      </div>
      
        
          <div class="yui-b" id="sidebar">
            
      <div class="sphinxsidebar">
        <div class="sphinxsidebarwrapper">
  <h3><a href="../../contents.html">Table Of Contents</a></h3>
  <ul>
<li><a class="reference internal" href="#">django.contrib.humanize</a><ul>
<li><a class="reference internal" href="#apnumber">apnumber</a></li>
<li><a class="reference internal" href="#intcomma">intcomma</a></li>
<li><a class="reference internal" href="#intword">intword</a></li>
<li><a class="reference internal" href="#naturalday">naturalday</a></li>
<li><a class="reference internal" href="#naturaltime">naturaltime</a></li>
<li><a class="reference internal" href="#ordinal">ordinal</a></li>
</ul>
</li>
</ul>

  <h3>Browse</h3>
  <ul>
    
      <li>Prev: <a href="gis/deployment.html">Deploying GeoDjango</a></li>
    
    
      <li>Next: <a href="messages.html">The messages framework</a></li>
    
  </ul>
  <h3>You are here:</h3>
  <ul>
      <li>
        <a href="../../index.html">Django 1.7.8.dev20150401230226 documentation</a>
        
          <ul><li><a href="../index.html">API Reference</a>
        
          <ul><li><a href="index.html"><tt class="docutils literal"><span class="pre">contrib</span></tt> packages</a>
        
        <ul><li>django.contrib.humanize</li></ul>
        </li></ul></li></ul>
      </li>
  </ul>

  <h3>This Page</h3>
  <ul class="this-page-menu">
    <li><a href="../../_sources/ref/contrib/humanize.txt"
           rel="nofollow">Show Source</a></li>
  </ul>
<div id="searchbox" style="display: none">
  <h3>Quick search</h3>
    <form class="search" action="../../search.html" method="get">
      <input type="text" name="q" />
      <input type="submit" value="Go" />
      <input type="hidden" name="check_keywords" value="yes" />
      <input type="hidden" name="area" value="default" />
    </form>
    <p class="searchtip" style="font-size: 90%">
    Enter search terms or a module, class or function name.
    </p>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
        </div>
      </div>
              <h3>Last update:</h3>
              <p class="topless">Apr 02, 2015</p>
          </div>
        
      
    </div>

    <div id="ft">
      <div class="nav">
    &laquo; <a href="gis/deployment.html" title="Deploying GeoDjango">previous</a>
     |
    <a href="../index.html" title="API Reference" accesskey="U">up</a>
   |
    <a href="messages.html" title="The messages framework">next</a> &raquo;</div>
    </div>
  </div>

      <div class="clearer"></div>
    </div>
  </body>
</html>